<template>
  <div class="goods-list">
    <goods-item :goods="item" v-for="(item,index) in goodsList" :key="index" class="goodsitem" />
  </div>
</template>

<script>
import GoodsItem from './goods-item'
import '@/mock/goods.js'
import requestH from '@/utils/requestH'

export default {
  name: 'GoodsList',
  components: { GoodsItem },
  props: {
    speciesId: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      goodsList: []
    }
  },
  created () {
    this.getGoodsList()
  },
  mounted () {

  },
  watch: {},
  computed: {},
  methods: {
    async getGoodsList() {
      try {
        // const abc = 's1'
        // const data = axios({
        //   method: 'GET',
        //   url: '/goodsList/' + abc
        // })
        // console.log(data);
        const { data } = await requestH({
          method: 'GET',
          url: '/goodsList',
          params: { id: this.speciesId }
        })
        console.log(data);
        this.goodsList = data.data
        console.log(this.goodsList);
      } catch (error) {
        this.$toast.fail('获取商品列表失败')
      }
    }
  }
}
</script>

<style scoped lang="less">
.goodsitem{
  margin: 20px 20px;
}
</style>
